package com.huanghao.controller;

import java.sql.Date;
import java.time.LocalDate;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huanghao.pojo.Commod;
import com.huanghao.pojo.PageBean;
import com.huanghao.pojo.Result;

@RestController
public class CommodController {
	
	@Autowired
	private com.huanghao.Service.CommodService EmpService;
	
//	查询
    @GetMapping("emp.do")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       						@RequestParam(defaultValue = "10") Integer pageSize,
                       String cName, Integer cNumber,Integer cPrice,
                       Integer cInventory,Integer cSales,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") Date begin,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") Date end){
    	PageBean pageBean= EmpService.page(page,pageSize,cName,cNumber,cPrice,cSales,begin,end,cInventory);
		System.out.println("查询");
        return Result.success(pageBean);
    }
	
//	删除 完成
	@DeleteMapping ("emp.do/{cNumber}") 
	public Result delete(@PathVariable List<Integer> cNumber) {
		System.out.println("删除商品");
		EmpService.delete(cNumber);
		return Result.success();
	}
	
	//新增 完成
    @PostMapping("emp.do")
    public Result add( Commod emp){
    	System.out.println("新增商品");
        EmpService.add(emp);
        return Result.success();
    }
    //更新 完成
    @PutMapping("emp.do")
    public  Result update( Commod emp){
    	System.out.println("更新商品");
        EmpService.update(emp);
        return Result.success();
    }
    //根据ID查询 成功
    @GetMapping("emp.do/{id}")
    public Result getById(@PathVariable Integer id){
    	System.out.println("查询id为"+id+"的信息");
        Commod emp   = EmpService.getById(id);
        return Result.success(emp);
    }
}